package admin

import (
	"context"
	"errors"

	"server/internal/svc"
	"server/internal/types"
	"server/models"
	"server/utils"

	"github.com/zeromicro/go-zero/core/logx"
)

type SpecValueDelLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSpecValueDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SpecValueDelLogic {
	return &SpecValueDelLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SpecValueDelLogic) SpecValueDel(req *types.IdJson) (resp string, err error) {
	if utils.GetData(&models.SkuSpecRelation{SpecValueID: req.Id}) {
		return "", errors.New("该规格值下有商品SKU，无法删除")
	}
	if err = utils.DeleteDataById(req.Id, &models.SpecValue{}); err != nil {
		return "", err
	}

	return "操作成功", nil
}
